﻿using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data;
using System.Linq;
namespace HelperPrototype.Reports {
    
    
    public partial class _DS_PhieuDeNghiMuaHang {
        partial class PhieuDeNghiMuaHang1DataTable
        {
        }
    
        partial class PhieuDeNghiMuaHangDataTable
        {
        }
        private string Ma = "";
        public void fillData(string ID)
        {

            this.Ma = ID;
            SqlConnection con = new SqlConnection(Properties.Settings.Default.myConnectionString);
            con.Open();

            string sql = "SELECT P.*,PH.MaHangHoa,PH.SoLuongDeNghi,PH.GiaThamKhao,PH.NhaCungCapThamKhao,PH.SoLuongMua,PH.SoLuongNhapKho,H.*" +
                " FROM PhieuDeNghiMuaHang P, PhieuDeNghiMuaHang_HangHoa PH,HangHoa H" +
            " WHERE P.MaPhieu = '" + ID + "' AND P.MaPhieu=PH.MaPhieuDeNghiMuaHang AND PH.MaHangHoa=H.MaHangHoa ";
            SqlDataAdapter dataAdaptor = new SqlDataAdapter(sql, con);
            dataAdaptor.Fill(this, "PhieuDeNghiMuaHang");
           
            //DS_PhieuMuaHang.PhieuDeNghiMuaHangDataTable tb = new DS_PhieuMuaHang.PhieuDeNghiMuaHangDataTable();
            //DS_PhieuMuaHangTableAdapters.PhieuDeNghiMuaHangTableAdapter da = new DS_PhieuMuaHangTableAdapters.PhieuDeNghiMuaHangTableAdapter();

            //da.Fill(tb, ID);

        }

        public void viewReport()
        {
            
            _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
            _DB.PhieuDeNghiMuaHang P = dc.PhieuDeNghiMuaHangs.Single(s => s.MaPhieu  == Ma);

           
           
            
            
            trash.CR_PhieuDeNghiMuaHang report = new trash.CR_PhieuDeNghiMuaHang();
            report.SetDataSource(this);
            report.SetParameterValue("MaPhieu", P.MaPhieu);
            report.SetParameterValue("MaNguoiTao", P.NguoiTao.Ten);
            report.SetParameterValue("NoiDung", P.NoiDung);
            ReportViewerForm form = new ReportViewerForm(report);
            form.ShowDialog();
        }
    }
}
